package cn.darkhorse.mesadmin.controller.device;


import cn.darkhorse.device.dto.MesRepairInfoDTO;
import cn.darkhorse.device.pojo.MesRepairInfo;
import cn.darkhorse.device.service.MesRepairInfoNewService;
import cn.darkhorse.device.vo.MesRepairApplyInfoVO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 报修单 前端控制器
 * </p>
 *
 * @author maoguanjun
 * @since 2022-11-11
 */
@RestController
@RequestMapping("/device/mesRepairInfoApply")
public class MesRepairInfoApplyController extends BaseController {
   @Resource
   private MesRepairInfoNewService mesRepairInfoService;

    /**
     * 列表
     * @param mesRepairInfoDTO
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public TableDataInfo list( MesRepairInfoDTO mesRepairInfoDTO){
        startPage();
        mesRepairInfoDTO.setDocumentType(0);
        List<MesRepairApplyInfoVO> mesRepairInfoVOS = mesRepairInfoService.listAll(mesRepairInfoDTO);
        return  getDataTable(mesRepairInfoVOS);
    }

    /**
     * 查看
     * @param id
     * @return
     */
    @RequestMapping(value = "/view",method = RequestMethod.POST)
    public AjaxResult view(Long id){
        if(null==id){
            return  AjaxResult.error("缺失参数！");
        }
        MesRepairApplyInfoVO mesRepairInfoVO = mesRepairInfoService.view(id);
        return AjaxResult.success(mesRepairInfoVO);
    }

    /**
     * 生成报修维修单号
     * @param type 0保修单1维修单
     * @return
     */
    @RequestMapping("/getApplyCode")
    public AjaxResult getApplyCode(Integer type){
        String code=mesRepairInfoService.getApplyCode(type);
        return AjaxResult.success(code);
    }
    /**
     * 保存
     * @param mesRepairInfo
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public AjaxResult save(@Validated @RequestBody MesRepairInfo mesRepairInfo){
        if(null==mesRepairInfo){
            return  AjaxResult.error("缺失参数！");
        }
        return AjaxResult.success(mesRepairInfoService.saveMesRepairInfo(mesRepairInfo));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public AjaxResult delete(@RequestParam("ids")List<Long> ids){
        if(ids.isEmpty()){
            return AjaxResult.error("缺失参数！");
        }
        boolean result= mesRepairInfoService.delete(ids);
        return AjaxResult.success(result);
    }


    /**
     * 审核
     * @param id 单据ID
     * @param approvalResult 审核结果 0立即维修1驳回
     * @param approvalOpinion 审核意见
     * @param nextUserId 下一审核人
     * @return
     */
    @RequestMapping(value = "/approval",method = RequestMethod.POST)
    public AjaxResult approval(Long id,Integer approvalResult, String approvalOpinion,Long nextUserId,String reason){
        if(null==id||null==approvalResult){
            return AjaxResult.error("缺失参数！");
        }
        boolean result= mesRepairInfoService.approval(id,approvalResult,approvalOpinion, nextUserId, reason);
        return AjaxResult.success(result);
    }
}

